home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / ins_msb / 9003 / bonus.bas next >
BASIC Source File  |  1990-03-01  |  2KB  |  65 lines

  1. 'PROGRAM - BONUS.BAS
  2.  
  3. 'This program demonstrates a way to save room
  4. 'in the DGROUP by storing string data outside of
  5. 'the program, but within the file.
  6.  
  7. DECLARE FUNCTION GetSizeOfFile& _
  8.                          (FileNumber AS INTEGER)
  9.  
  10. 'Initialize and read the data
  11.  
  12. CLS                                'Use the filename of
  13. OPEN "I", 1, "NEWTEST.EXE"    '  this program
  14. Size& = GetSizeOfFile&(1)    'Retrieve program LEN
  15. InitLoc& = Size& + 1            'Set beginning data 
  16. SEEK #1, InitLoc&                '  location to 1 past
  17.                                     '  end of EXE portion
  18. LINE INPUT #1, ID$            'Get the first variable
  19. IDLen% = LEN(ID$) + 2        'Set the field length
  20.                                     '  plus cr/lf
  21. CtrPos& = InitLoc& + IDLen%    'Calculate position
  22. LINE INPUT #1, Counter$            'Get next variable
  23. CtrLen% = LEN(Counter$)            'Calculate its LEN
  24. Counter% = VAL(Counter$) + 1    'Increment value
  25. Counter$ = RIGHT$("   " + STR$(Counter%), CtrLen%)
  26.  
  27. 'Display the data read from the end of the file
  28.  
  29. PRINT "Identification: "; ID$
  30. PRINT "Number of times executed: "; Counter%
  31.  
  32. CLOSE 1        'Close file so we can reopen it and
  33.                 '  write data
  34.  
  35. OPEN "B", 1, "NEWTEST.EXE"        'Use binary mode
  36. PUT 1, CtrPos&, Counter$        'Rewrite new value
  37. CLOSE 1                                'Close file again
  38. END
  39.  
  40. FUNCTION GetSizeOfFile& (FileNumber AS INTEGER)
  41.  
  42. 'This function returns the actual size of 
  43. 'programs in a long variable.  Pass the routine
  44. 'the file number used to open the file
  45.  
  46. 'Read 1st 6 bytes of hdr
  47.    A$ = INPUT$(6, FileNumber)
  48. 'Calculate the number of partial pages used in
  49. '  the program file, if any.  This number is stored
  50. '  in bytes 3 and 4.
  51.    Fraction& = ASC(MID$(A$, 4)) * 256& _
  52.                 + ASC(MID$(A$, 3))
  53. 'Calculate the number of whole pages used to 
  54. '  store the file.                
  55.    Pages& = ASC(MID$(A$, 6)) * 256& _
  56.              + ASC(MID$(A$, 5))
  57. 'If there are any fractional pages subtract 1
  58. '  from the pages count.
  59.    IF Fraction& THEN Pages& = Pages& - 1
  60. 'Each page is 512 bytes long so multiply 512
  61. '  times the number of pages and add any
  62. '  fractional bytes to the total.
  63.    GetSizeOfFile& = Pages& * 512& + Fraction&
  64. END FUNCTION
  65.